package com.googlecode.ddplan.dwr.steps;

import java.util.HashMap;
import java.util.Map;

import org.jbehave.core.annotations.Given;

import com.googlecode.ddplan.dwr.domain.Crane;
import com.googlecode.ddplan.dwr.domain.Location;
import com.googlecode.ddplan.dwr.domain.Location.Type;
import com.googlecode.ddplan.dwr.domain.Pile;
import com.googlecode.ddplan.dwr.domain.Robot;

public class DWRSteps {
	private Map<String, Object> allSymbols;

	public DWRSteps(Map<String, Object> allSymbols) {
		this.allSymbols = allSymbols;
	}

	@Given("a location $location")
	public void aLocation(String locationName) {
		Location location = new Location(locationName);
		allSymbols.put(locationName, location);
	}

	@Given("another location $newLocation on the east of $location")
	public void aLocationOnEastOf(String newLocationName, String locationName) {
		Location location = (Location) allSymbols.get(locationName);
		Map<Type, Location> adjacentLocations = new HashMap<Type, Location>();
		adjacentLocations.put(Type.EAST, location);
		Location newLocation = new Location(newLocationName, adjacentLocations);
		allSymbols.put(newLocationName, newLocation);
	}

	@Given("a crane $crane in $location")
	public void aLocation(String craneName, String locationName) {
		Location location = (Location) allSymbols.get(locationName);
		Crane crane = new Crane(craneName);
		location.addCrane(crane);
		allSymbols.put(craneName, crane);
	}

	@Given("a pile $pile with number $number in $location")
	public void aPile(String pileName, int number, String locationName) {
		Location location = (Location) allSymbols.get(locationName);
		Pile pile = new Pile(pileName, number);
		location.attachPile(pile);
		allSymbols.put(pileName, pile);
	}

	@Given("a robot $robot")
	public void aRobot(String robotName) {
		Robot robot = new Robot(robotName);
		allSymbols.put(robotName, robot);
	}

}
